package com.itheima.d5_regex;

/**
 * 目标：掌握正则表达式的书写规则
 */
public class RegexTest2 {
    public static void main(String[] args) {
        // 1、字符类(只能匹配单个字符)
        System.out.println("\"a\".matches(\"[a-zA-Z_0-9]\") = " + "a".matches("[a-zA-Z_0-9]"));
        // 2、预定义字符(只能匹配单个字符)  .  \d  \D   \s  \S  \w  \W
        System.out.println("\"a\".matches(\"\\\\d\") = " + "a".matches("\\d"));
        System.out.println("\"1\".matches(\"\\\\d\") = " + "1".matches("\\d"));
        // \转义
        System.out.println("\"");
        // \n \t

        // 3、数量词： ?   *   +   {n}   {n, }  {n, m}
        System.out.println("\"123123\".matches(\"\\\\d{5,19}\") = " + "123123".matches("\\d{5,19}"));
        System.out.println("\"123\".matches(\"\\\\d{5,19}\") = " + "123".matches("\\d{5,19}"));

        // 4、其他几个常用的符号：忽略大小写 (?i) 、 或 | 、  分组()
        System.out.println("\"A\".matches(\"(?i)a\") = " + "A".matches("(?i)a"));

        System.out.println("\"a\".matches(\"[a|b|c]\") = " + "a".matches("[a|b|c]"));

        System.out.println("\"aabbcc\".matches(\"(\\\\w{2}){3}\") = " + "aabbcc".matches("(\\w{2}){3}"));
        System.out.println("\"abbcc\".matches(\"(\\\\w{2}){3}\") = " + "abbcc".matches("(\\w{2}){3}"));


        // 需求1：要求要么是3个小写字母，要么是3个数字。 [a-z]{3}|\d{3}
        System.out.println("123".matches("[a-z]{3}|\\d{3}"));//true
        System.out.println("abc".matches("[a-z]{3}|\\d{3}"));//true
        System.out.println("a12".matches("[a-z]{3}|\\d{3}"));//false

        // 需求2：必须是”我爱“开头，中间可以是至少一个”编程“，最后至少是1个”666“。 我爱(编程)+(666)+
        String str = "我爱编程编程666666";
        System.out.println(str.matches("我爱(编程)+(666)+"));    //true
    }
}
